using System.Collections.Generic;
using System.Linq;
using UnityEngine;


    [CreateAssetMenu(fileName = "ChangedChessInSkillRange-改变位置的棋子是否在这个技能范围", menuName = "Skill/Target/ChangedChessInSkillRange-改变位置的棋子是否在这个技能范围")]
    public class ChangedChessInSkillRange : TargetSelectorBase
    {
        public override List<Chess> SelectTargets(Chess chess ,GameEvent e)
        {
            if (e is not ChangeEvent changeEvent)
            {
                Debug.LogWarning("传输的GameEvent是错误类型");
                return null;
            }

            if (changeEvent.ChangeChess == chess)
            {
                return null;
            }
            
            var targetPositions =
                chess.GetChessSide() == ChessSide.Player1
                    ? chess.chessDate.skillRange.rangeType == RangeType.Normal
                        ? Math.GetTargetPosition(chess.ChessDetail.Position,
                            chess.chessDate.skillRange.vector2IntMode)
                        : chess.chessDate.skillRange.vector2IntMode
                    : chess.chessDate.skillRange.rangeType == RangeType.Normal
                        ? Math.GetEnemyTargetPosition(chess.ChessDetail.Position,
                            chess.chessDate.skillRange.vector2IntMode)
                        : chess.chessDate.skillRange.vector2IntMode;

            return targetPositions.Contains(changeEvent.ChangeChess.ChessDetail.Position) ? new List<Chess>(){changeEvent.ChangeChess} : null;
        }
        
        
        
    }
